import IWebSocket from "./IWebSocket";
import webSocket from "./webSocket";

export default class SocketInstance implements IWebSocket{
    private socket:webSocket
    private static _instance:SocketInstance=new SocketInstance();

    constructor() 
    { 
        //将webSocket实例化
        this.socket=new webSocket()
    }
    
    //单例模式
    public static get instance()
    {
        if(!this._instance)
        {
            this._instance=new SocketInstance()
        }
        return this._instance
    }


    /**发送请求 */
    sendRequest(requestCode:any,actionCode:any,data:any)
    {
        //打包数据
        let msg=this.socket.packData(requestCode,actionCode,data)
        //发送数据
        this.socket.sendMsg(msg);
    }

}